define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'car/old_auditing/index' + location.search,
                    add_url: 'car/old_auditing/add',
                    edit_url: 'car/old_auditing/edit',
                    del_url: 'car/old_auditing/del',
                    multi_url: 'car/old_auditing/multi',
                    import_url: 'car/old_auditing/import',
                    table: 'car_old',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                fixedNumber:7,
                showExport:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'nickname', title: "归属人",operate: false},
                        {field: 'type', title: "车源分类", searchList: {"0":"二手车","1":"新车"}, formatter: Table.api.formatter.label},
                        {field: 'car_brand_name', title: __('Car_brand_id')},
                        {field: 'car_series_name', title: __('Car_series_id')},
                        {field: 'car_models_name', title: __('Car_models_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'VIN', title: __('Vin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cc', title: __('Cc'), operate:'BETWEEN'},
                        {field: 'cc_unit', title: __('Cc_unit'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'car_image', title: __('Car_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'prove_image', title: '车辆铭牌', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'car_video', title: __('Car_video'), operate: 'false',previewfile:true},


                        // {field: 'registration_time', title: __('Registration_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'factory_date', title: __('Factory_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},

                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'base_price', title: __('Base_price'), operate:'BETWEEN'},
                        // {field: 'is_price', title: __('Is_price'), searchList: {"0":"否","1":"是"}, formatter: Table.api.formatter.status},
                        {field: 'transfer_num', title: __('Transfer_num')},
                        {field: 'odometer_km', title: __('Odometer_km'), operate:'BETWEEN'},
                        // {field: 'year_inspect_date', title: __('Year_inspect_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'compulsory_insurance_date', title: __('Compulsory_insurance_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'mortgage', title: __('Mortgage'), searchList: {"0":"无抵押","1":"有抵押"}, formatter: Table.api.formatter.label},
                        {field: 'use_character', title: __('Use_character'), searchList: {"0":"非营运","1":"网约车退役"}, formatter: Table.api.formatter.label},
                        {field: 'car_describe', title: __('Car_describe'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'label_ids', title: __('Label_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'sparkle_ids', title: __('Sparkle_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'key_num', title: __('Key_num')},
                        // {field: 'spare_tire', title: __('Spare_tire'), operate: 'LIKE'},
                        // {field: 'car_colour', title: __('Car_colour'), operate: 'LIKE'},
                        // {field: 'prove_image', title: __('Prove_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'test_report_file', title: __('Test_report_file'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'ssss_report_image', title: __('Ssss_report_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'danger_report_image', title: __('Danger_report_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'defect_images', title: '瑕疵照片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'odometer_images', title: '里程表图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        // {field: 'gearbox', title: __('Gearbox')},
                        // {field: 'new_price', title: __('New_price'), operate:'BETWEEN'},
                        // {field: 'load_people_num', title: __('Load_people_num')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"0":"下架","1":"上架"}, formatter: Table.api.formatter.status},
                        {field: 'verify_status', title: "审核状态", searchList: {"0":"未审核","1":"通过","2":"驳回"}, formatter: Table.api.formatter.status},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        // {field: 'operate', title: "审核", table: table, events: Table.api.events.operate, formatter: function(value,row,index){
                        //     if (row.verify_status==0){
                        //         return "<button onclick='shenhe("+row.id+")'   class='shenhe btn-success'>通过</button> <button onclick='bohui("+row.id+")'  class='btn-primary'>驳回</button>"
                        //
                        //     } else {
                        //         return ""
                        //     }
                        //     }
                        // },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


            // top.window.Backend.api.sidebar({
            //     'car/old_auditing':0
            // });


        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

$("#c-car_series_id").data("params", function (obj) {
    //obj为SelectPage对象
    return {custom: {brand_id: $("#c-car_brand_id").val()}};
});

$("#c-car_models_id").data("params", function (obj) {
    //obj为SelectPage对象
    return {custom: {series_id: $("#c-car_series_id").val()}};
});

function piliangshenhe() {
    var temp = $("#table").bootstrapTable('getSelections')
    var ids = []
    if (temp.length > 0) {
        temp.forEach((item)=>{
            ids.push(item.id)
        })
    }
    layer.confirm(`确定该操作吗？`, {
            title: "通过",
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            $.ajax({
                url: "car/old_auditing/shenhes", //请求接口
                type: "post",
                dataType: "json",
                data: {"ids": ids}, //请求参数
                success: function (data) {
                    layer.confirm(data.msg, {
                        btn: ['确定'] //按钮
                    }, function (index2) {
                        Fast.api.refreshmenu(); //刷新列表
                        layer.close(index2); //关闭窗口
                    })
                    return false;
                }
            })

        }
    );
}

function shenhe(id){
    $.ajax({
        url: "car/old_auditing/shenhe", //请求接口
        type: "post",
        dataType: "json",
        data: {"id":id}, //请求参数
        success: function (data) {
            window.parent.location.reload();
        }
    })
    // layer.confirm(`确定该操作吗？`, {
    //         title:"审核通过",
    //         btn: ['确定', '取消'] //按钮
    //     }, function (index) {
    //
    //
    //     }
    // );
}

$(document).on('click', '#bohui', function() {
    let val = $("input[name='row[verify_info]']").val()
    let id = $("input[name='row[id]']").val()

    $.ajax({
        url: "car/old_auditing/bohui", //请求接口
        type: "post",
        dataType: "json",
        data: {
            "id":id,
            "verify_info":val
        },
        success: function (data) {
            window.parent.location.reload();
            return false;
        }
    })
})




